<?php
$server = new swoole_server('0.0.0.0',3333);
$server->on('connect', function (\Swoole\Server $ser, $fd) {
     echo "====connect  success====".PHP_EOL;
});
$server->on('receive', function (\Swoole\Server $ser, $fd, $reactor_id, $data) {
   echo "====receive  success====".PHP_EOL;
   /**
   //设置一个定时器，每2秒执行一次打印
    $ser->tick(2000,function ($ser,$fd){
       echo "=====".$fd.PHP_EOL;
    });

    //设置一个定时器 3秒后只执行一次打印
    $ser->after(3000,function () use ($ser, $fd, $data) {
       echo "====after===".$data.PHP_EOL;
    });

    //延后执行一个函数
    $ser->defer(function ()use ($data, $fd) {
      echo "====after===".$data.PHP_EOL;
    });
   */

   //清除定时器
   //设置一个定时器，每3秒执行一次打印
    $timer_id = $ser->tick(3000,function () use ($data) {
      echo "====tick===".$data.PHP_EOL;
   });

   //10秒之后清除定时器
   $ser->after(10000,function ($ser, $taskId) use ($fd,$data,$timer_id) {
      $ser->clearTimer($timer_id);
   });

});
$server->start();